package com.ruoyi.webs.utils.weixinlogin;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;


public class CoreService {
    public static String processRequest(HttpServletRequest request) {
        String respXML = null;
        String replyMessage = "未知的消息类型";
        try {
            String content, picUrl;
            Map<String, String> requestMap = MessageUtil.parseXml(request);

            String fromUserName = requestMap.get("FromUserName");

            String toUserName = requestMap.get("ToUserName");

            String strMsgType = requestMap.get("MsgType");

            EnumMessageType msgType = Enum.<EnumMessageType>valueOf(EnumMessageType.class, strMsgType);

            BaseMessage baseMessage = new BaseMessage();
            baseMessage.setFromUserName(fromUserName);
            baseMessage.setToUserName(toUserName);
            switch (msgType) {

                case text:
                    content = requestMap.get("Content");
                    if (!content.equals("?") && !content.equals("？")) {


                        if ("2".equals(content)) {

                            replyMessage = "请输入天气加城市的名字,如:天气@北京";
                            break;
                        }
                        if (content.contains("天气@")) {
                            String[] str = content.split("@");
                            replyMessage = MessageUtil.getWeather(str[1]);
                            break;
                        }
                        if ("6".equals(content)) {


                            replyMessage = "https://www.baidu.com/";
                            break;
                        }
                        if ("8".equals(content)) {


                            replyMessage = "https://www.souhu.com/";
                            break;
                        }
                        replyMessage = "您发的是文字消息,消息内容为:" + content + ",我厉害吗?";
                    }
                    break;


                case image:
                    picUrl = requestMap.get("PicUrl");
                    replyMessage = "您发的是图片消息，图片地址是：" + picUrl;
                    break;
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        return respXML;
    }
}